<?php

namespace ShowStop\TelevisionBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * ShowStop\TelevisionBundle\Entity\Series
 *
 * @ORM\Table(name="user_edited_series")
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks
 */
class EditSeries
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
    
    /**
    * @var integer $seriesid
    *
    * @ORM\Column(name="series_ID", type="integer")
    */
    private $seriesID;
    
    /**
    * @var integer $userID
    *
    * @ORM\Column(name="user_id", type="integer")
    */
    private $userID;

    /**
     * @var string $name
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /**
     * @var text $description
     *
     * @ORM\Column(name="description", type="text", nullable="true")
     */
    private $description;
    
    /**
    * @var text comment
    *
    * @ORM\Column(name="comment", type="text", nullable="true")
    */
    private $comment;
    
    /**
    * @var text $source
    *
    * @ORM\Column(name="source", type="text", nullable="true")
    */
    private $source;

    /**
     * @var string $first_aired
     *
     * @ORM\Column(name="first_aired", type="string", nullable="true")
     */
    private $first_aired;

    /**
     * @var string $network
     *
     * @ORM\Column(name="network", type="string", length=50, nullable="true")
     */
    private $network;

    /**
     * @var string $status
     *
     * @ORM\Column(name="status", type="string", length=50, nullable="true")
     */
    private $status;
    
    /**
    * @var string $submission_status
    *
    * @ORM\Column(name="submission_status", type="string", length=50, nullable="true")
    */
    private $submission_status;

    
    /**
    * @var string $return_date
    *
    * @ORM\Column(name="return_date", type="string", nullable="true")
    */
    private $return_date;
    
    /**
    * @var string $path
    *
    * @ORM\Column(name="path", type="string", nullable="true")
    */
    private $path;
    
    /**
    * @Assert\File(maxSize="6000000")
    */
    public $file;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
    
    /**
    * Get id
    *
    * @return integer
    */
    public function getSeriesId()
    {
    	return $this->seriesID;
    }
    
    
    /**
    * Set seriesid
    *
    * @param string $name
    */
    public function setSeriesID($seriesID)
    {
    	$this->seriesID = $seriesID;
    }
    
    /**
    * Get user
    *
    * @return integer
    */
    public function getUserId()
    {
    	return $this->userID;
    }
    
    
    /**
     * Set seriesid
     *
     * @param string $name
     */
    public function setUserID($userID)
    {
    	$this->userID = $userID;
    }

    /**
     * Set name
     *
     * @param string $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set description
     *
     * @param text $description
     */
    public function setDescription($description)
    {
        $this->description = $description;
    }

    /**
     * Get description
     *
     * @return text 
     */
    public function getDescription()
    {
        return $this->description;
    }
    
    /**
    * Set comment
    *
    * @param text $comment
    */
    public function setComment($comment)
    {
    	$this->comment = $comment;
    }
    
    /**
     * Get comment
     *
     * @return text
     */
    public function getComment()
    {
    	return $this->comment;
    }
    
    /**
    * Set source
    *
    * @param text $source
    */
    public function setSource($source)
    {
    	$this->source = $source;
    }
    
    /**
     * Get source
     *
     * @return text
     */
    public function getSource()
    {
    	return $this->source;
    }


    /**
     * Set first_aired
     *
     * @param string $firstAired
     */
    public function setFirstAired($firstAired)
    {
        $this->first_aired = $firstAired;
    }

    /**
     * Get first_aired
     *
     * @return string 
     */
    public function getFirstAired()
    {
        return $this->first_aired;
    }

    /**
     * Set network
     *
     * @param string $network
     */
    public function setNetwork($network)
    {
        $this->network = $network;
    }

    /**
     * Get network
     *
     * @return string 
     */
    public function getNetwork()
    {
        return $this->network;
    }

    /**
     * Set status
     *
     * @param string $status
     */
    public function setStatus($status)
    {
        $this->status = $status;
    }

    /**
     * Get status
     *
     * @return string 
     */
    public function getStatus()
    {
        return $this->status;
    }
    
    /**
    * Set file
    *
    * @param file $file
    */
    public function setFile($file)
    {
    	$this->file = $file;
    }
    
    /**
     * Get $file
     *
     * @return file
     */
    public function getFile()
    {
    	return $this->file;
    }
    
    /**
    * Set submission_status
    *
    * @param string $submission_status
    */
    public function setSubmissionStatus($submission_status)
    {
    	$this->submission_status = $submission_status;
    }
    
    /**
     * Get submission_status
     *
     * @return string
     */
    public function getSubmissionStatus()
    {
    	return $this->submission_status;
    }
    
    /**
    * Set return_date
    *
    * @param string $returnDate
    */
    public function setReturnDate($returnDate)
    {
    	$this->return_date = $returnDate;
    }
    
    /**
     * Get return_date
     *
     * @return string
     */
    public function getReturnDate()
    {
    	return $this->return_date;
    }

    public function getAbsolutePath()
    {
        return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->path;
    }

    public function getWebPath()
    {
        return null === $this->path ? null : $this->getUploadDir().'/'.$this->path;
    }

    protected function getUploadRootDir()
    {
        // the absolute directory path where uploaded documents should be saved
        return __DIR__.'/../../../../web/'.$this->getUploadDir();
    }

    protected function getUploadDir()
    {
        // get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view.
        return 'uploads/documents';
    }
    
	/**
     * @ORM\PrePersist()
     * @ORM\PreUpdate()
     */
    public function preUpload()
    {
        if ( null !== $this->file ) {
            // do whatever you want to generate a unique name
            $this->path = uniqid().'.'.$this->file->guessExtension();
        }
    }

    /**
     * @ORM\PostPersist()
     * @ORM\PostUpdate()
     */
    public function upload()
    {
        if (null === $this->file) {
            return;
        }

        // you must throw an exception here if the file cannot be moved
        // so that the entity is not persisted to the database
        // which the UploadedFile move() method does automatically
        $this->file->move($this->getUploadRootDir(), $this->path);

        unset($this->file);
    }

    /**
     * @ORM\PostRemove()
     */
    public function removeUpload()
    {
        if ($file = $this->getAbsolutePath()) {
            unlink($file);
        }
    }
    
}